package admin_api

import (
	"github.com/gin-gonic/gin"
	"shop/admin/admin_service"
	"shop/service"
	"shop/utils/convertutil"
	"shop/utils/result"
	"shop/utils/sessionutil"
)

func GetOrderList(c *gin.Context) {
	pageNo := convertutil.ParseInt(c.DefaultQuery("pageNo", "1"))
	pageSize := convertutil.ParseInt(c.DefaultQuery("pageSize", "10"))
	orderStatus := convertutil.ParseInt(c.DefaultQuery("orderStatus", "0"))
	result.RenderResult(c, admin_service.GetOrderList(sessionutil.GetShopIdFromCtx(c), pageNo, pageSize, orderStatus))
}

func UpdateOrderStatus(c *gin.Context) {
	params := new(admin_service.UpdateOrderStatusParams)
	if err := c.ShouldBindJSON(params); err != nil {
		result.RenderResult(c, result.Fail("参数格式错误: "+err.Error()))
		return
	}

	result.RenderResult(c, admin_service.UpdateOrderStatus(sessionutil.GetShopIdFromCtx(c), params))
}

// PrintOrderInfo 打印订单小票
func PrintOrderInfo(c *gin.Context) {
	result.RenderResult(c, service.PrinterOrder(c.Param("id")))
}
